global class CourseToAnnouncement {

    public CourseToAnnouncement(ApexPages.StandardController controller) {
    } 
     
   public Id Course_Id{get; set;}
      public PageReference verifyParameters() {
        if (ApexPages.currentPage().getParameters().containsKey('paramCourse_Id')){
              Course_Id = ApexPages.currentPage().getParameters().get('paramCourse_Id');
              CreateAnnouncement(Course_Id);
       }  
        return null;
    }
    
    @RemoteAction
    WebService static void CreateAnnouncement(ID id) {

        //create a announcement with data of course.

       //List<Course__c> list_courses;
       Course__c current_course = new Course__c(); 
       current_course = [SELECT Id, Name FROM Course__c WHERE Id =:id LIMIT 1];
             
       String name_course = current_course.Name;
       Announcement__c ann = new Announcement__c();
       ann.Name = name_course;
       insert ann;
       Id id_ann = ann.Id;

       List<Course_participant__c> lst_Crse_part = [Select Name, Id, Course_participant__c, Course__c FROM Course_participant__c WHERE Course__c=:id];

       //Database.insert(ann);
       for(Course_participant__c id_p_c : lst_Crse_part){
           A_Task__c task_announcement = new A_Task__c();
           task_announcement.Name = ann.Name;
           task_announcement.Announcement__c = ann.Id;
           task_announcement.Description__c = 'Go to course using the URL';
           task_announcement.URL__c = 'https://softtek.sboxconf.cs8.force.com/apex/course?id='+ current_course.Id;
           insert task_announcement;
           //Database.insert(task_announcement);
           A_Task_User__c ATask_Usr = new A_Task_User__c();
           ATask_Usr.Announcement_Task__c = task_announcement.Id;
           ATask_Usr.User__c = id_p_c.Course_participant__c;
           insert ATask_Usr;
          // Database.insert(ATask_Usr);
           
        }
//       Database.Update();
    }

}